<!-- 按钮组件 -->
<template>
  <div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="!taskreportList || checkPermission([permissionPrefix + 'add'])"
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="[permissionPrefix + 'add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if="!taskreportList || checkPermission([permissionPrefix + 'remove']) && selectedRow.ct_fun_no != 1000"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="[permissionPrefix + 'remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if="!taskreportList || checkPermission([permissionPrefix + 'export'])"
          type="info"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="[permissionPrefix + 'export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if="checkPermission([permissionPrefix + 'sign']) && $route.name.indexOf('S') != -1"
          type="info"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="handleBatchSign"
          v-hasPermi="[permissionPrefix + 'sign']"
        >签发</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-help" size="mini" @click="handleHelp">帮助</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button plain icon="el-icon-pie-chart" size="mini" @click="handleStatistics">统计</el-button>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { checkPermi } from '@/utils/permission.js'
import store from '@/store/index'
import { getFunNo } from '@/utils/party'
import {NAME} from '@/utils/config'
export default {
  name: 'dynamicButton',
  props: {
    buttonData: {
      type: Object,
      default: () => {
        return {}
      },
    },
    permissionPrefix: {
      type: String,
      default: () => {
        return 'dynamic:button:'
      },
    },
    //   任务上报 前端控制显示新增  删除  导出 按钮
    taskreportList:{
      type:Boolean,
      default:true,
    }
  },
  data() {
    return {
      // 非单个禁用
      single: false,
      // 非多个禁用
      multiple: false,
      showSearch: true,
      funNo: getFunNo(this.taskreportList ?this.$route : this.$router.resolve({ name: NAME }).route),
      // 选中的数组
      ids: [],
      selectedRow: {
        selectedCt: {
          handleType: 'add',
        },
        ct_fun_no: getFunNo(this.taskreportList ?this.$route : this.$router.resolve({ name: NAME }).route),
        functionData: {},
      },
    }
  },
  methods: {
    // 单据签发
    handleBatchSign() {
      this.$emit('handleBatchSign')
    },
    // 帮助按钮
    handleHelp() {
      this.$router.push('/spsPublicRouter/helpPreview?funNo=' + this.funNo)
    },
    // 检查权限
    checkPermission(permissions) {
      return checkPermi(permissions)
    },
    //导出按钮
    handleExport() {
      this.$emit('handleExport')
    },
    //新增按钮
    handleAdd() {
      const handleTypeModel = {
        funNo: this.selectedRow.ct_fun_no,
        handleType: this.selectedRow.selectedCt.handleType,
      }
      store.dispatch('setHandleType', handleTypeModel).then(() => {
        this.$emit('updateValue', this.selectedRow)
      })
      store.dispatch('openShowMaster', this.selectedRow.ct_fun_no)
    },
    //删除按钮
    handleDelete() {
      this.$emit('handleRemove')
    },
    // 统计信息显示
    handleStatistics() {
      this.$emit('handleStatistics')
    },
  },
}
</script>
<style lang="scss" scoped>
</style>
